home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
c01lab4.zip
/
LRMRDR
/
LRM_CODE.ZIP
/
MAKE_DAF.A
< prev
next >
Wrap
Text File
|
1992-05-01
|
4KB
|
122 lines
-- Make_DAF by Rick Conn
-- Scan Ada LRM Chapter Files and build Direct-Access Files of
-- them.
-- COPYRIGHT NOTICE
-- Ada LRM Reader - Interactive Presentation of the Ada LRM
-- Copyright (C) 1992 Richard Conn
--
-- This program is free software; you can redistribute it
-- and/or modify it under the terms of the GNU General Public
-- License Version 1 as published by the Free Software
-- Foundation.
--
-- This program is distributed in the hope that it will be
-- useful, but WITHOUT ANY WARRANTY; without even the implied
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU General Public License for more
-- details. You should have received a copy of the GNU General
-- Public License along with this program; if not, write to the
-- Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
-- 02139, USA. See the ABOUT screens for further information,
-- including information on how to contact the author.
with SYSDEP;
with DAF_Handler;
with Console; -- CS Parts
with Input_File; -- CS Parts
procedure Make_DAF is
FN_String_Length : constant := 10; -- length of file name string
subtype FN_STRING is STRING(1..FN_String_Length);
type FN_VECTOR is array (NATURAL range <>) of FN_STRING;
File_Names : constant FN_VECTOR := (
"chap01.doc", "chap02.doc", "chap03.doc", "chap04.doc",
"chap05.doc", "chap06.doc", "chap07.doc", "chap08.doc",
"chap09.doc", "chap10.doc", "chap11.doc", "chap12.doc",
"chap13.doc", "chap14.doc", "chapaa.doc", "chapab.doc",
"chapac.doc", "chapad.doc", "chapae.doc", "chapaf.doc",
"chapco.doc", "chapfo.doc", "chaphe.doc", "chapin.doc",
"chappo.doc", "chapxx.doc"
);
Max_Blank : constant := 3; -- max number of blank lines in a row
----------------------------------------------------------------
function Is_Blank_Line (Item : in STRING) return BOOLEAN is
Result : BOOLEAN := TRUE;
begin -- Is_Blank_Line
for I in Item'RANGE loop
if Item(I) > ' ' then
Result := FALSE;
exit;
end if;
end loop;
return Result;
end Is_Blank_Line;
----------------------------------------------------------------
-- Convert the indicated file into a DAF file.
procedure Process_File (Name : in STRING) is
Input_File_ID : Input_File.FILE_TYPE;
Output_File_Name : FN_STRING := "chapxx.daf";
Inline : STRING (1..SYSDEP.Max_String_Length);
Inlast : NATURAL;
Number_of_Consecutive_Blank_Lines : NATURAL := 0;
begin -- Process_File
-- open input file, create output file
Output_File_Name(1..6) := Name(1..6);
Console.Put_Line ("Processing File " & Name & " into " &
Output_File_Name);
Input_File.Open (Input_File_ID, Name);
DAF_Handler.Create (Output_File_Name);
-- loop to end of input text file
while not Input_File.End_of_File (Input_File_ID) loop
-- get next line from input file and check for blank
Input_File.Get_Line (Input_File_ID, Inline, Inlast);
if Is_Blank_Line (Inline(1..Inlast)) then
Number_of_Consecutive_Blank_Lines :=
Number_of_Consecutive_Blank_Lines + 1;
else
Number_of_Consecutive_Blank_Lines := 0;
end if;
-- add line to output file if not too many blank lines in a row
if Number_of_Consecutive_Blank_Lines <= Max_Blank then -- OK to print
DAF_Handler.Write (Inline(1..Inlast));
end if;
end loop;
-- Close files
Input_File.Close (Input_File_ID);
DAF_Handler.Close_Create;
exception
when others =>
Console.Put_Line ("Error on File " & Name);
end Process_File;
begin -- Make_DAF
Console.Put_Line ("Direct Access File (DAF) Builder");
for I in SYSDEP.Intro_Copyright_Notice'RANGE loop
Console.Put_Line (SYSDEP.Intro_Copyright_Notice(I));
end loop;
-- Build DAF files
for I in File_Names'RANGE loop
Process_File (File_Names(I));
end loop;
end Make_DAF;